package cn.baage.campus.service.impl;

import cn.baage.campus.config.properties.MinioProperties;
import cn.baage.campus.model.vo.UploadFileRspVO;
import cn.baage.campus.service.FileService;
import cn.baage.campus.utils.MinioUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description: 文件Service实现
 * @Author: 八阿哥
 * @url: baage.cn
 * @Version: 1.0
 **/
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class FileServiceImpl implements FileService {

    private final MinioUtils minioUtils;
    private final MinioProperties minioProperties;


    /**
     * 上传文件
     *
     * @param file 文件
     * @return 上传结果
     */
    @Override
    public UploadFileRspVO uploadFile(MultipartFile file) {
        String path = minioUtils.uploadFile(file);
        String url = String.format("%s/%s/%s", minioProperties.getEndpoint(), minioProperties.getBucketName() ,path);
        return new UploadFileRspVO(path, url);
    }

}
